package com.sk.bilibili.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sk.bilibili.bean.DailyReward;
import com.sk.bilibili.bean.Member;
import com.sk.bilibili.dto.MemberInfo;
import com.sk.bilibili.dto.QrCode;
import com.sk.bilibili.other.R;
import com.sk.bilibili.service.MemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @author 邵康
 * @date 2021/11/22 23:08
 */
@CrossOrigin
@RestController
@RequestMapping("/member")
@Api(tags = "用户")
public class MemberController {

    @Autowired
    private MemberService memberService;

    @ApiOperation("add")
    @PostMapping("/add")
    public R<Void> add(Member member) {
        return memberService.add(member);
    }

    @ApiOperation("deleteRes")
    @GetMapping("/delete")
    public R<Void> delete(Integer id) {
        return memberService.delete(id);
    }

    @ApiOperation("更新当前用户信息")
    @PostMapping("/update")
    public R<Void> update(Member member) {
        return memberService.update(member);
    }

    @ApiOperation("pageSearch")
    @GetMapping("/page")
    public R<IPage<Member>> page(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer size) {
        return memberService.page(page, size);
    }

    @ApiOperation("注册:电话,密码,昵称,验证码都是必须的  注册成功 创建默认收藏夹")
    @PostMapping("/register")
    public R<Member> register(@RequestBody MemberInfo memberInfo) {
        return memberService.register(memberInfo);
    }

    @ApiOperation("登录:电话,密码/验证码")
    @PostMapping("/login")
    public R<Member> login(@RequestBody MemberInfo memberInfo) {
        return memberService.login(memberInfo);
    }

    @ApiOperation("每日用户登录")
    @GetMapping("/dailyLogin")
    public R<Void> dailyLogin(){
        return memberService.dailyLogin();
    }

    @ApiOperation("退出登录 销毁对应的session")
    @GetMapping("/logout")
    public R<Void> logout(){
        return memberService.logout();
    }

    @ApiOperation("根据用户Id获取用户信息若不传入Id 获取当前用户信息")
    @GetMapping("/getMember")
    public R<Member> getMember(Integer id){
        return memberService.getMember(id);
    }

}
